import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Logger } from './common/logger/logger';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: ['error', 'warn'],
  });

  // 添加全局验证管道
  app.useGlobalPipes(new ValidationPipe());

  const config = app.get(ConfigService);
  // 设置 api 访问前缀
  const prefix: any = config.get<string>('API_PREFIX');
  app.setGlobalPrefix(prefix);

  // 日志
  const logger = app.get(Logger);
  app.useLogger(logger);
  // console.log('APP_PORT', config.get<number>('APP_PORT'));

  // doc
  const swaggerConfig = new DocumentBuilder()
    .setTitle('Cats example')
    .setDescription('The cats API description')
    .setVersion('1.0')
    // .addTag('cats')
    .build();
  const documentFactory = () =>
    SwaggerModule.createDocument(app, swaggerConfig);
  SwaggerModule.setup('docs', app, documentFactory);

  await app.listen(3332);
}
bootstrap();
